<?php

class Admin_AuthController extends Zend_Controller_Action
{

    public function init()
    {
    }

    public function indexAction()
    {
        // action body
    }

    public function loginAction()
    {
    	$form = new Admin_Form_Login();
    	$form->setMethod('post');
    	$request = $this->getRequest();
        if ($request->isPost()) {
        	$form_data = $request->getPost();
        	if ($form->isValid($form_data)) {
	        	$user_name = $form->getValue('user_name');
	        	$password = $form->getValue('password');
	        	$config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/config.ini', 'production');
	        	if (($user_name == $config->admin->user_login) && (md5($password) == $config->admin->password->md5)) {
	        		$auth_session = new Zend_Session_Namespace('Auth');
	        		$auth_session->__set('user', $user_name);
	        		$this->_helper->redirector->gotoRoute(array('controller' => 'index', 'action' => 'index'), 'admin');
	        	} 
        	} else {
        		$form->populate($request->getPost());
        	}
        }
    	$this->view->form = $form;
    }

    public function logoutAction()
    {
        // action body
    }


}





